Various: Less CSTR() abuse.
garmin_tables. Use QString as arg type.
int hour =0;
int min =0;
int sec =0;
- char* ampm = NULL;
int ac;
- ampm = (char*) xmalloc(strlen(s) + 1);
+ char* ampm = (char*) xmalloc(strlen(s) + 1);
ac = sscanf(s, format, &hour, &min, &sec, ampm);
/* If no time format in arg string, assume AM */
if (ac < 4) {
*/
#include "garmin_tables.h"
+#include "src/core/logging.h"
#include "jeeps/gpsmath.h"
#include <stdio.h>
}
grid_type
-gt_lookup_grid_type(const char* grid_name, const char* module)
+gt_lookup_grid_type(const char* grid_name, const QString& module)
{
grid_mapping_t* g;
for (g = gt_mps_grid_names; (g->shortname); g++) {
- if ((case_ignore_strcmp(grid_name, g->shortname) == 0) ||
- (case_ignore_strcmp(grid_name, g->longname) == 0)) {
+ if (QString::compare(grid_name, g->shortname, Qt::CaseInsensitive) == 0 ||
+ QString::compare(grid_name, g->longname,Qt::CaseInsensitive) == 0) {
return g->grid;
}
}
- fatal("%s: Unsupported grid (%s)! See GPSBabel help for supported grids.\n",
- module, grid_name);
+ Fatal() << module << ": Unsupported grid (" << grid_name <<
+ ". See GPSBabel help for supported grids.\n";
return grid_unknown; /* (warnings) */
}
result = GPS_Math_Get_Datum_Name(datum_index);
for (d = gt_mps_datum_names; (d->jeeps_name); d++)
- if (case_ignore_strcmp(result, d->jeeps_name) == 0) {
+ if (QString::compare(result, d->jeeps_name, Qt::CaseInsensitive) == 0) {
return d->mps_name;
}
}
int
-gt_lookup_datum_index(const char* datum_str, const char* module)
+gt_lookup_datum_index(const char* datum_str, const QString& module)
{
datum_mapping_t* d;
int result;
const char* name = datum_str;
for (d = gt_mps_datum_names; (d->jeeps_name); d++) {
- if (case_ignore_strcmp(name, d->mps_name) == 0) {
+ if (QString::compare(name, d->mps_name, Qt::CaseInsensitive) == 0) {
name = d->jeeps_name;
break;
}
result = GPS_Lookup_Datum_Index(name);
+ // Didn't get a hit? Try again after modifying the lookup.
if (result < 0) {
QString tmp = QString(datum_str) + " mean";
- result = GPS_Lookup_Datum_Index(CSTR(tmp));
+ result = GPS_Lookup_Datum_Index(tmp);
}
- is_fatal(result < 0,
- "%s: Unsupported datum (%s)! See GPSBabel help for supported datums.",
- module, datum_str);
-
+ if (result < 0) {
+ Fatal() << module << ": Unsupported datum (" << datum_str <<
+ "). See GPSBabel help for supported datums.";
+ }
return result;
}
}
uint32_t
-gt_color_value_by_name(const char* name)
+gt_color_value_by_name(const QString& name)
{
unsigned int i;
for (i = 0; i < GT_COLORS_CT; i++)
- if (case_ignore_strcmp(gt_colors[i].name, name) == 0) {
+ if (QString::compare(gt_colors[i].name, name, Qt::CaseInsensitive) == 0) {
return gt_colors[i].rgb;
}
}
int
-gt_color_index_by_name(const char* name)
+gt_color_index_by_name(const QString& name)
{
unsigned int i;
for (i = 0; i < GT_COLORS_CT; i++)
- if (case_ignore_strcmp(name, gt_colors[i].name) == 0) {
+ if (QString::compare(gt_colors[i].name, name, Qt::CaseInsensitive) == 0) {
return i;
}
unsigned char gt_switch_display_mode_value(const unsigned char display_mode, const int protoid, const char device);
-grid_type gt_lookup_grid_type(const char* grid_name, const char* module);
+grid_type gt_lookup_grid_type(const char* grid_name, const QString& module);
const char* gt_get_mps_grid_longname(const grid_type grid, const char* module);
-int gt_lookup_datum_index(const char* datum_str, const char* module);
+int gt_lookup_datum_index(const char* datum_str, const QString& module);
const char* gt_get_mps_datum_name(const int datum_index);
uint32_t gt_color_value(const unsigned int garmin_index);
-uint32_t gt_color_value_by_name(const char* name);
-int gt_color_index_by_name(const char* name);
+uint32_t gt_color_value_by_name(const QString& name);
+int gt_color_index_by_name(const QString& name);
int gt_color_index_by_rgb(const int rgb);
const char* gt_color_name(const unsigned int garmin_index);
rte_head->rte_desc = cdatastr;
break;
case tt_garmin_rte_display_color:
- rte_head->line_color.bbggrr = gt_color_value_by_name(CSTR(cdatastr));
+ rte_head->line_color.bbggrr = gt_color_value_by_name(cdatastr);
break;
case tt_rte_number:
rte_head->rte_num = cdatastr.toInt();
trk_head->rte_desc = cdatastr;
break;
case tt_garmin_trk_display_color:
- trk_head->line_color.bbggrr = gt_color_value_by_name(CSTR(cdatastr));
+ trk_head->line_color.bbggrr = gt_color_value_by_name(cdatastr);
break;
case tt_trk_number:
trk_head->rte_num = cdatastr.toInt();
break;
case 1:
/* waypoint name */
- wpt_tmp->shortname = csv_stringtrim(str, "");
+ wpt_tmp->shortname = str.trimmed();
break;
case 2:
/* degrees latitude */
break;
case 10:
/* Description */
- wpt_tmp->description = csv_stringtrim(str, "");
+ wpt_tmp->description = str.trimmed();
break;
case 11:
/* pointer direction 0,1,2,3 bottom,top,left,right */
}
if (wpt->description != wpt->shortname) {
- gbfprintf(file_out, "%s", CSTRc(wpt->description));
+ gbfputs(wpt->description, file_out);
if (!wpt->gc_data->placer.isEmpty()) {
- gbfprintf(file_out, " by %s", CSTR(wpt->gc_data->placer));
+ gbfputs(" by ", file_out);
+ gbfputs(wpt->gc_data->placer, file_out);
}
}
if (wpt->gc_data->terr) {
xfree(hint);
}
} else if (!wpt->notes.isEmpty() && (wpt->description.isEmpty() || wpt->notes != wpt->description)) {
- gbfprintf(file_out, "\n%s\n", CSTRc(wpt->notes));
+ gbfputs("\n", file_out);
+ gbfputs(wpt->notes, file_out);
+ gbfputs("\n", file_out);
}
fs_gpx = NULL;
logpart = xml_findfirst(curlog, "groundspeak:type");
if (logpart) {
- gbfprintf(file_out, "%s by ", CSTR(logpart->cdata));
+ gbfputs(logpart->cdata, file_out);
+ gbfputs(" by ", file_out);
}
logpart = xml_findfirst(curlog, "groundspeak:finder");
if (logpart) {
- gbfprintf(file_out, "%s on ", CSTR(logpart->cdata));
+ gbfputs(logpart->cdata, file_out);
+ gbfputs(" on ", file_out);
}
logpart = xml_findfirst(curlog, "groundspeak:date");
} else {
base = (*str < 'G') ? 16 : 31;
}
-
+ // FIXME: this is wrong. 0123456789ABCDEFGHJKMNPQRTVWXYZ ILOSU are omitted.
+ // That nobody has noticed is a good hint nobody cares...
while ((cx = *str++)) {
int num;
return res;
}
-// static int unicsv_parse_time(const char *str, int *msec, time_t *date);
-
static time_t
unicsv_parse_date(const char* str, int* consumed)
{
*date = ldate;
}
}
-
ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &ms);
is_fatal(ct < 5, MYNAME ": Could not parse time string (%s).\n", str);
if (ct == 6) {
}
if FIELD_USED(fld_date) {
if (wpt->creation_time.toTime_t() >= SECONDS_PER_DAY) {
- struct tm tm;
- char buf[32];
- time_t time = wpt->GetCreationTime().toTime_t();
-
+ QDateTime dt;
if (opt_utc) {
- time += atoi(opt_utc) * SECONDS_PER_HOUR;
- tm = *gmtime(&time);
+ dt = wpt->GetCreationTime().toUTC();
+ // We might wrap to a different day by overriding the TZ offset.
+ dt = dt.addSecs(atoi(opt_utc) * SECONDS_PER_HOUR);
} else {
- const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = *localtime(&tt);
+ dt = wpt->GetCreationTime();
}
- tm.tm_year += 1900;
- tm.tm_mon += 1;
- snprintf(buf, sizeof(buf), "%04d/%02d/%02d", tm.tm_year, tm.tm_mon, tm.tm_mday);
- gbfprintf(fout, "%s%s", unicsv_fieldsep, buf);
+ QString date = dt.toString("yyyy/MM/dd");
+ gbfputs(unicsv_fieldsep, fout);
+ gbfputs(date, fout);
} else {
gbfputs(unicsv_fieldsep, fout);
}
}
if FIELD_USED(fld_time) {
if (wpt->creation_time.isValid()) {
- struct tm tm;
- char buf[32], msec[12];
- time_t time = wpt->GetCreationTime().toTime_t();
-
+ QTime t;
if (opt_utc) {
- time += atoi(opt_utc) * SECONDS_PER_HOUR;
- tm = *gmtime(&time);
+ t = wpt->GetCreationTime().toUTC().time();
+ t = t.addSecs(atoi(opt_utc) * SECONDS_PER_HOUR);
} else {
- const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = *localtime(&tt);
+ t = wpt->GetCreationTime().time();
}
- snprintf(buf, sizeof(buf), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
-
- int millisecs = wpt->GetCreationTime().time().msec();
- if (millisecs > 0) {
- int len = 3;
-
- while (len && (millisecs % 10 == 0)) {
- millisecs /= 10;
- len--;
- }
- snprintf(msec, sizeof(msec), ".%0*d", len, millisecs);
- strcat(buf, msec);
+ QString out;
+ if (t.msec() > 0) {
+ out = t.toString("hh:mm:ss.z");
+ } else {
+ out = t.toString("hh:mm:ss");
}
- gbfprintf(fout, "%s%s", unicsv_fieldsep, buf);
+ gbfputs(unicsv_fieldsep, fout);
+ gbfputs(out, fout);
} else {
gbfputs(unicsv_fieldsep, fout);
}
/*
Misc utilities.
- Copyright (C) 2002-2005 Robert Lipe, robertlipe+source@gpsbabel.org
+ Copyright (C) 2002-2014 Robert Lipe, robertlipe+source@gpsbabel.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
xol_write_string(const QString& name, const QString& str)
{
if (!str.isEmpty()) {
- QString temp = strenquote(str, '"');
- gbfprintf(fout, " %s=%s", CSTR(name), CSTR(temp));
+ QString out = name + "=" + strenquote(str, '"');
+ gbfputs(out, fout);
}
}